package com.example.spring.others;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

/**
 * @author majie
 * @date 2018/6/25.
 */
@Component
public class MyFactoryBean implements FactoryBean<Cat> {

    private Cat cat;

    @Override
    public Cat getObject( ) throws Exception {
        System.out.println(1111);
        if (cat == null) {
            synchronized (this) {
                if (cat == null) {
                    Cat cat = new Cat();
                    cat.setAge(1);
                    cat.setName("mao mao");
                    this.cat = cat;
                }
            }
        }
        return cat;
    }

    @Override
    public Class<?> getObjectType( ) {
        return Cat.class;
    }

    @Override
    public boolean isSingleton( ) {
        return true;
    }
}
